package cn.lg.soar.general.entity;

import cn.lg.soar.common.data.tree.ITreeSource;
import cn.lg.soar.database.base.entity.BaseEntity;
import com.alibaba.excel.annotation.ExcelProperty;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.annotation.JsonIgnore;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Getter;
import lombok.Setter;
import lombok.experimental.Accessors;

import java.io.Serializable;

/**
 * 区域
 * @author luguoxiang
 * @since 2022-08-04
 * 开源项目：https://gitee.com/lgx1992/lg-soar 求star！请给我star！请帮我点个star！
 */
@Getter
@Setter
@Accessors(chain = true)
@ApiModel(value = "Region", description = "区域")
@TableName("lg_general_region")
public class Region extends BaseEntity implements ITreeSource<Integer> {

    private static final long serialVersionUID = 2642755837365554838L;

    @ExcelProperty(value = "ID")
    @ApiModelProperty(value = "ID")
    @TableId(type = IdType.INPUT)
    private Integer id;

    @ExcelProperty(value = "地址名称")
    @ApiModelProperty(value = "地址名称")
    private String name;

    @ExcelProperty(value = "排序")
    @ApiModelProperty(value = "排序")
    private Integer sort;

    @ExcelProperty(value = "状态(0启用，1禁用)")
    @ApiModelProperty(value = "状态(0启用，1禁用)")
    private Integer status;

    @Override
    public Integer getId() {
        return id;
    }

    @Override
    public Integer getParentId() {
        if ((id % 10000) == 0) {
            return 0;
        }
        if ((id % 100) == 0) {
            return id / 10000 * 10000;
        }
        return id / 100 * 100;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    @JsonIgnore
    @Override
    public Serializable primaryKey() {
        return this.id;
    }

}
